home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / flight-of-the-museum.swf / scripts / com / google / analytics / utils / URL.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  3.3 KB  |  133 lines

  1. package com.google.analytics.utils
  2. {
  3.    public class URL
  4.    {
  5.        
  6.       
  7.       private var _url:String;
  8.       
  9.       public function URL(url:String = "")
  10.       {
  11.          super();
  12.          _url = url.toLowerCase();
  13.       }
  14.       
  15.       public function get domain() : String
  16.       {
  17.          var parts:Array = null;
  18.          if(hostName != "" && hostName.indexOf(".") > -1)
  19.          {
  20.             parts = hostName.split(".");
  21.             switch(parts.length)
  22.             {
  23.                case 2:
  24.                   return hostName;
  25.                case 3:
  26.                   if(parts[1] == "co")
  27.                   {
  28.                      return hostName;
  29.                   }
  30.                   parts.shift();
  31.                   return parts.join(".");
  32.                   break;
  33.                case 4:
  34.                   parts.shift();
  35.                   return parts.join(".");
  36.             }
  37.          }
  38.          return "";
  39.       }
  40.       
  41.       public function get path() : String
  42.       {
  43.          var _path:String = _url;
  44.          if(_path.indexOf("://") > -1)
  45.          {
  46.             _path = String(_path.split("://")[1]);
  47.          }
  48.          if(_path.indexOf(hostName) == 0)
  49.          {
  50.             _path = _path.substr(hostName.length);
  51.          }
  52.          if(_path.indexOf("?") > -1)
  53.          {
  54.             _path = String(_path.split("?")[0]);
  55.          }
  56.          if(_path.charAt(0) != "/")
  57.          {
  58.             _path = "/" + _path;
  59.          }
  60.          return _path;
  61.       }
  62.       
  63.       public function get protocol() : Protocols
  64.       {
  65.          var proto:String = String(_url.split("://")[0]);
  66.          switch(proto)
  67.          {
  68.             case "file":
  69.                return Protocols.file;
  70.             case "http":
  71.                return Protocols.HTTP;
  72.             case "https":
  73.                return Protocols.HTTPS;
  74.             default:
  75.                return Protocols.none;
  76.          }
  77.       }
  78.       
  79.       public function get hostName() : String
  80.       {
  81.          var hostname:String = _url;
  82.          if(hostname.indexOf("://") > -1)
  83.          {
  84.             hostname = String(hostname.split("://")[1]);
  85.          }
  86.          if(hostname.indexOf("/") > -1)
  87.          {
  88.             hostname = String(hostname.split("/")[0]);
  89.          }
  90.          if(hostname.indexOf("?") > -1)
  91.          {
  92.             hostname = String(hostname.split("?")[0]);
  93.          }
  94.          if(protocol == Protocols.file || protocol == Protocols.none)
  95.          {
  96.             return "";
  97.          }
  98.          return hostname;
  99.       }
  100.       
  101.       public function get subDomain() : String
  102.       {
  103.          if(domain != "" && domain != hostName)
  104.          {
  105.             return hostName.split("." + domain).join("");
  106.          }
  107.          return "";
  108.       }
  109.       
  110.       public function get search() : String
  111.       {
  112.          var _search:String = _url;
  113.          if(_search.indexOf("://") > -1)
  114.          {
  115.             _search = String(_search.split("://")[1]);
  116.          }
  117.          if(_search.indexOf(hostName) == 0)
  118.          {
  119.             _search = _search.substr(hostName.length);
  120.          }
  121.          if(_search.indexOf("?") > -1)
  122.          {
  123.             _search = String(_search.split("?")[1]);
  124.          }
  125.          else
  126.          {
  127.             _search = "";
  128.          }
  129.          return _search;
  130.       }
  131.    }
  132. }
  133.